/*!
\file
	CppFormater.h
\brief
	Declaration of CppFormater.
\details
\bug
	none
\todo
	node
\date
	February 24, 2008 - first version of the file.
	April 20, 2008 - added support of inharitance.
\author
	Copyright (C) 2008 Vadym Hulakov, mailto:hulakov@gmail.com.
	All rights reserved.
*/

#ifndef CPPFORMATTER_H
#define CPPFORMATTER_H

class DataTypesManager;
class Attribute;
class Method;
class Parameter;

#include <iostream>

#include "Formatter.h"

namespace ObjectModel
{
	//! Class for generating C++ code
	class CppFormatter : public Formatter
	{
		int _maxLineLength;

	public:
		//! @name Construction and destruction
		//@{
		//! Constructor
		//! @param [in] manager
		//!		Data types manager that contains data type
		//!		that must be converted to C++ code
		CppFormatter(TypeHierarchy& manager);
		//@}
		
		typedef std::map<std::wstring, std::wstring> Results;
		const Results& results() { return _results; }
		
		//! @name Public methods
		//@{
		//! Perform C++ code generation
		void build();
		//@}
		
		void setMaxLineLength(int length) { _maxLineLength = length; }
		int maxLineLength() { return _maxLineLength; }


	private:
		
		const wchar_t* to_cpp(enum ClassMemberAccess access) const;
		void to_cpp_data_type(const Type& data_type, std::wstring& name);
		bool format_comment(std::wstring& comment, 
			int offset_before, int offset_after);
		void to_cpp(const Type& data_type, bool declaration);
		bool to_cpp(const Type& data_type, std::wostream &stream, 
			bool declaration, int offset);
		bool to_cpp(const Type& data_type, const Attribute& info, 
			std::wostream &stream, bool declaration, int offset);
		bool to_cpp(const Type& data_type, const Method& info, 
			std::wostream &stream, bool declaration, int offset);
		bool to_cpp(const Type& data_type, 
			const Parameter& info, std::wostream &stream);
		void print_member_access(std::wostream &stream, 
			ClassMemberAccess access);
		
		//! Generate header witch will be putted on the start of a source file.
		//! @param [in] data_type
		//!		Data type information witch will be used for header generation. 
		//! @param [in] stream
		//!		Output stream. 
		//! @param [in] declaration
		//!		Logical flag witch indicates generate declaration or definition. 
		bool generate_header(const Type& data_type, std::wostream &stream, 
			bool declaration);

		bool generate_includes(const ClassType& data_type,
			std::wostream &stream, bool declaration);
		void generate_filename(const Type& data_type,
			bool declaration, std::wstring &filename);

		Results _results;
	};
}
#endif // CPPFORMATTER_H
